#include "VectorInformation.h"
#ifndef VECTOR_INFORMATION_CLASS_IMPL
#define VECTOR_INFORMATION_CLASS_IMPL

VectorInformation VectorInformation::operator-() {
    return VectorInformation(-x, -y, -z);
}
// 向量与标量的乘法与除法运算
VectorInformation VectorInformation::operator*(double scalar) {
    return VectorInformation(x * scalar, y * scalar, z * scalar);
}
VectorInformation VectorInformation::operator*=(double scalar) {
    (x *= scalar, y *= scalar, z *= scalar);
    return this[0];
}
VectorInformation VectorInformation::operator/(double scalar) {
    return VectorInformation(x / scalar, y / scalar, z / scalar);
}
VectorInformation VectorInformation::operator/=(double scalar) {
    (x /= scalar, y /= scalar, z /= scalar);
    return *this;
}






// 计算向量平方根(向量的模),符号||a||表示a向量的平方根
double VectorInformation::SquareVectorDescription() {
    return sqrt(x * x + y * y + z * z);
}
// 打印向量
void VectorInformation::ShowVectorInformation() {
    cout << "Vector Print:" << endl<<"\t";
    cout << "[" << FormatOutputFloatValue(x) << "," << FormatOutputFloatValue(y) << "," << FormatOutputFloatValue(z) << "]" << endl;
}
// 向量[x,y,z]的标准化=[x/√￣(x^2+y^2+z^2),y/√￣(x^2+y^2+z^2),z/√￣(x^2+y^2+z^2)]
void VectorInformation::Normalize() {
    double squareValue = this->SquareVectorDescription();
    this->x = x / squareValue;
    this->y = y / squareValue;
    this->z = z / squareValue;
}
// 向量与向量的加法减法运算
VectorInformation VectorInformation::operator+(VectorInformation ved) {
    return VectorInformation(x + ved.x, y + ved.y, z + ved.z);
}


VectorInformation VectorInformation::operator-(VectorInformation ved) {
    return VectorInformation(x - ved.x, y - ved.y, z - ved.z);
}
VectorInformation VectorInformation::operator+=(VectorInformation ved) {
    (x += ved.x, y += ved.y, z += ved.z);
    return *this;
}

VectorInformation VectorInformation::operator-=(VectorInformation ved) {
    (x -= ved.x, y -= ved.y, z -= ved.z);
    return *this;
}
// 向量点乘 a*b=a.x*b.x+a.y*b.y+a.z*b.z+a.n*b.n+...=||a||*||b||*cosθ
double VectorInformation::operator*(VectorInformation ved) {
    return x * ved.x + y * ved.y + z * ved.z;
}

VectorInformation VectorInformation::operator*=(VectorInformation ved) {
    (x *= ved.x, y *= ved.y, z *= ved.z);
    return *this;
}


VectorInformation operator* (int scalar, VectorInformation vecd) {
    return vecd * scalar;
}


// 获取两个向量点之间距离,公式:√￣(vecd1.x-vecd2.x)^2+(vecd1.y-vecd2.y)^2+(vecd1.z-vecd2.z)^2
double GetDistanceBetweenTwoVectorPoints(VectorInformation& vecd1, VectorInformation vecd2) {
    // 分别计算x,y,z之间的差值
    double dx = vecd1.GetX() - vecd2.GetX();
    double dy = vecd1.GetY() - vecd2.GetY();
    double dz = vecd1.GetZ() - vecd2.GetZ();
    return sqrt(dx * dx + dy * dy + dz * dz);
}
// 计算余铉角度
double GetCosAngle(VectorInformation& vecd1, VectorInformation vecd2) {
    // 计算两个向量商的积
    double sum = vecd1.SquareVectorDescription() * vecd2.SquareVectorDescription();
    // 计算点乘公式:a*b=||a||*||b||*cosθ
    double pointsMul = vecd1 * vecd2;
    // 计算余铉角弧度
    double cos = acos(pointsMul / sum);
    // 弧度*180/PI=角度
    return cos * 180 / PI;
}

// 计算向量叉乘
VectorInformation CrossMultiply(VectorInformation& vecd1, VectorInformation vecd2) {
    return VectorInformation(vecd1.GetY() * vecd2.GetZ() - vecd1.GetZ() * vecd2.GetY()
        , vecd1.GetZ() * vecd2.GetX() - vecd1.GetX() * vecd2.GetZ()
        , vecd1.GetX() * vecd2.GetY() - vecd1.GetY() * vecd2.GetX()
    );
}
#endif // !VECTOR_DESCRIPTION_CLASS_IMPL
